<?php

class SQLFilter extends SQLExpression {

    private $variable;
    private $operator;
    private $value;

    public function __construct($variable, $operator, $value, $ignoreTransformation = false) {
        $this->variable = $variable;
        $this->operator = $operator;
        if ($ignoreTransformation) {
            $this->value = $value;
        } else {
            $this->value = self::transform($value);
        }
    }

    private static function transform($value) {
        switch (gettype($value)) {
            case 'array':
                $arr = array();
                foreach ($value as $v) {
                    $arr[] = self::transform($v);
                }
                return '(' . implode(',', $arr) . ')';

            case 'boolean':
                return $value ? 'TRUE' : 'FALSE';

            case 'integer':
            case 'double':
                return $value;

            case 'string':
                return "'{$value}'";

            case 'object':
                if ($value instanceof Exprension) {
                    return $value->dump();
                } elseif ($value instanceof Instruction) {
                    return '(' . $value->getInstruction() . ')';
                }
                return 'NULL';

            case 'NULL':
            default:
                return 'NULL';
        }
    }

    public function dump() {
        return "{$this->variable} {$this->operator} {$this->value}";
    }

}

?>
